# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-cucumber-messages
pkgver=21.0.1
pkgrel=1
pkgdesc="Protocol Buffer messages for Cucumber's inter-process communication"
arch=(any)
url='https://github.com/cucumber/messages/tree/main/ruby'
license=(MIT)
depends=(ruby)
makedepends=(ruby-cucumber-compatibility-kit ruby-rake ruby-rspec)
options=(!emptydirs)
source=(https://github.com/cucumber/messages/archive/v$pkgver/cucumber-messages-$pkgver.tar.gz)
sha256sums=('bb8067fc73c0e1f84e5e2501a72d83d62e90a423b7d8c4d805ac54ffd77cbde4')

build() {
  local _gemdir="$(gem env gemdir)"
  cd messages-$pkgver/ruby
  gem build cucumber-messages.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    cucumber-messages-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd messages-$pkgver/ruby
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd messages-$pkgver/ruby
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
